﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Import.aspx.cs" Inherits="Web.Views.LotteryPerson.Import" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>导入开票数据</title>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="../../Content/assets/css/admin/font.css">
        <link rel="stylesheet" href="../../Content/assets/lib/layui/css/layui.css">
    <link rel="stylesheet" href="../../Content/assets/css/admin/xadmin.css">
    <script type="text/javascript" src="../../Content/assets/js/jquery.min.js"></script>
    <script src="../../Content/assets/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../Content/assets/lib/xadmin.js"></script>
    <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]--></head>
<body>
<div class="x-body">
  <form class="layui-form">
      <div class="layui-form-item">
      <label for="L_username" class="layui-form-label">Excel文件 </label>
      <div class="layui-input-inline">
        <div class="layui-upload">
          <input type="text" id="nvc_path" name="nvc_path" lay-verify="required" value="" autocomplete="off" class="layui-input" />
          <button type="button" class="layui-btn" id="excel">浏览</button>
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <label for="L_repass" class="layui-form-label"> </label>
      <button  class="layui-btn bgcolor-blue" lay-filter="add" lay-submit="add"> 保存 </button>
    </div>
  </form>
</div>
<script>
    var controller = 'LotteryPerson';
    function publish(url, data) {

        $.post(url, { data: JSON.stringify(data.field) }, function (result) {
            layer.close(layer.index);
            if (result.status) {
                layer.alert("导入成功", { icon: 6 }, function () {
                    // 获得frame索引
                    var index = parent.layer.getFrameIndex(window.name);
                    //关闭当前frame
                    parent.layer.close(index);
                    //parent.window.reloadtable();
                    parent.window.location = parent.window.location;
                });

            } else {
                layer.alert(result.message);
            }

        }, 'json');
    }
    //初始化
    $(function () {
        var id = '<%=ViewData["id"] %>';
        $.post('/' + controller + '/getEntityByID', { id: id }, function (message) {
            //var entity = '<%=ViewData["Entity"] %>';

            if (message.status == 1) {
                var obj = message.data;
            } else {
                layer.alert(message.message);
            }
        }, 'json');


    });

    layui.use(['form', 'upload', 'laydate', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
          , layer = layui.layer
          , laydate = layui.laydate
          , upload = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#excel'
            , accept: 'file' //普通文件,
            , url: '/LotteryPerson/Upload?id=<%=ViewData["id"]%>'
            , before: function (obj) {
                //示范一个公告层
                layer.open({
                    type: 1
                    , title: false //不显示标题栏
                    , closeBtn: false
                    , area: '300px;'
                    , shade: 0.8
                    , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                    , btnAlign: 'c'
                    , moveType: 1 //拖拽模式，0或者1
                    , content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">文件上传中....</div>'
                    , success: function (layero) {
                    }
                });
            }
            , done: function (res) {
                layer.close(layer.index);
                //如果上传失败
                if (res.status == 0) {
                    return layer.msg('上传失败');
                }
                //上传成功
                $('#nvc_path').val(res.data);
            }
            , error: function () {
                layer.close(layer.index);
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });

        //监听提交
        form.on('submit(add)', function (data) {
            console.log(data);
            //示范一个公告层
            layer.open({
                type: 1
                    , title: false //不显示标题栏
                    , closeBtn: false
                    , area: '300px;'
                    , shade: 0.8
                    , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                    , btnAlign: 'c'
                    , moveType: 1 //拖拽模式，0或者1
                    , content: '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">数据导入中....</div>'
                    , success: function (layero) {
                    }
            });
            publish('/LotteryPerson/importsave?id=<%=ViewData["id"]%>', data);
            //发异步，把数据提交给php

            return false;
        });
        form.on('submit(cancel)', function (data) {
            // 获得frame索引
            var index = parent.layer.getFrameIndex(window.name);
            //关闭当前frame
            parent.layer.close(index);

            return false;
        });

    });
</script>
</body>
</html>
